Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch HTTP client from hackney to finch #758

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

savhappy
Copy link
Collaborator

@savhappy savhappy commented Jul 29, 2024

Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start!! Left a few comments to address 🙃

@@ -253,30 +253,30 @@ defmodule Sentry.Config do
The maximum number of attempts to send an event to Sentry.
"""
],
hackney_opts: [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep hackney_opts and deprecate them if we want this to not be a breaking change. NimbleOptions supports deprecating options, check out the docs for that.

This also applies to the options below.

Copy link
Collaborator Author

@savhappy savhappy Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we need to keep the option:

    client: [
      type: :atom,
      type_doc: "`t:module/0`",
      default: Sentry.HackneyClient,
      doc: """
      """
    ]

and the module HackneyClient?? @whatyouhide

HTTP client, you'll have to implement your own `Sentry.HTTPClient`. See the
documentation for `Sentry.HTTPClient` for more information.

Finch is built on top of NimblePool. If you need to set other pool configuration options,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to nimble_pool's repo here?

Comment on lines 15 to 16
see "Pool Configuration Options" in the source code for details on the possible map values.
[finch configuration options](https://github.com/sneako/finch/blob/main/lib/finch.ex)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't point people to source code, that can change (especially main). Let's link to Finch for docs

Comment on lines +515 to +626
@spec finch_opts() :: keyword()
def finch_opts, do: fetch!(:finch_opts)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we use these?

@savhappy savhappy changed the title Sav/switch hackney to finch Switch HTTP client from hackney to finch Aug 6, 2024
@whatyouhide whatyouhide added this to the 11.0.0 milestone Aug 20, 2024
@aselder
Copy link
Contributor

aselder commented Feb 11, 2025

Any progress on this?

A CVE (with no patched version) was issued against Hackney today: benoitc/hackney#751

@savhappy
Copy link
Collaborator Author

savhappy commented Feb 11, 2025

@aselder we backlogged this yesterday but perhaps we should continue with revisions and make the switch? @whatyouhide @sl0thentr0py

A quick fix is to configure your own HTTP client.

@whatyouhide
Copy link
Collaborator

@savhappy yeah let's pursue this. Where we at? What we need to do?

@savhappy savhappy force-pushed the sav/Switch-hackney-to-finch branch 3 times, most recently from 36a8c52 to fbd58f0 Compare February 13, 2025 07:01
@savhappy
Copy link
Collaborator Author

@whatyouhide it's in good shape after I fix the conflicts. I'll rerequest a review when ready

@savhappy savhappy force-pushed the sav/Switch-hackney-to-finch branch from b20ab52 to c479fb2 Compare February 15, 2025 18:21
@savhappy
Copy link
Collaborator Author

@whatyouhide when we deprecate the :hackney_opts in the config file we get a ton of warnings from NimbleOptions when it tries to validate the config opts. So our tests are cluttered with these warnings:

warning: :hackney_opts option is deprecated. Use Finch instead as default client. (nimble_options 1.1.1) lib/nimble_options.ex:575: NimbleOptions.validate_value/3 (nimble_options 1.1.1) lib/nimble_options.ex:561: NimbleOptions.validate_option/3 (nimble_options 1.1.1) lib/nimble_options.ex:542: NimbleOptions.reduce_options/2 (elixir 1.17.2) lib/enum.ex:4858: Enumerable.List.reduce/3 (elixir 1.17.2) lib/enum.ex:2585: Enum.reduce_while/3 (nimble_options 1.1.1) lib/nimble_options.ex:535: NimbleOptions.validate_options/2 (nimble_options 1.1.1) lib/nimble_options.ex:508: NimbleOptions.validate_options_with_schema_and_path/3 (sentry 10.8.1) lib/sentry/config.ex:505: Sentry.Config.validate!/1 (sentry 10.8.1) lib/sentry/config.ex:661: Sentry.Config.put_config/2 (sentry 10.8.1) test/support/test_helpers.ex:32: anonymous fn/2 in Sentry.TestHelpers.put_test_config/1 (elixir 1.17.2) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3 (sentry 10.8.1) test/support/test_helpers.ex:24: Sentry.TestHelpers.put_test_config/1 test/sentry/test_test.exs:13: Sentry.TestTest.__ex_unit_setup_0/1 test/sentry/test_test.exs:1: Sentry.TestTest.__ex_unit__/2 (ex_unit 1.17.2) lib/ex_unit/runner.ex:478: ExUnit.Runner.exec_test_setup/2 (ex_unit 1.17.2) lib/ex_unit/runner.ex:411: anonymous fn/2 in ExUnit.Runner.spawn_test_monitor/4 (stdlib 5.2.3) timer.erl:270: :timer.tc/2 (ex_unit 1.17.2) lib/ex_unit/runner.ex:407: anonymous fn/6 in ExUnit.Runner.spawn_test_monitor/4

How do I quiet them or deprecate in a more subtle way?

@savhappy savhappy force-pushed the sav/Switch-hackney-to-finch branch from c479fb2 to f13edfd Compare February 15, 2025 18:59
@whatyouhide
Copy link
Collaborator

whatyouhide commented Feb 17, 2025

How do I quiet them or deprecate in a more subtle way?

Start with

hackney_opts: [
  type: ...,
  ...
] ++ if(Mix.env() == :test, do: [], else: [deprecated: "..."])

@savhappy savhappy force-pushed the sav/Switch-hackney-to-finch branch from 9f4dff2 to ee7e3e5 Compare February 21, 2025 06:10
@savhappy savhappy force-pushed the sav/Switch-hackney-to-finch branch from c925a56 to c7d2df9 Compare February 28, 2025 23:36
@savhappy savhappy force-pushed the sav/Switch-hackney-to-finch branch from c7d2df9 to 8f3fc16 Compare March 1, 2025 00:30
Copy link

@jjcarstens jjcarstens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 So excited for this! ❤️

Sorry for the random review. We were starting on a quick HTTP client to replace Hackney and saw this was in progress, so I am very interested in helping push it through since it is so close. Happy to contribute changes if needed 🤠

xref: [exclude: [:hackney, :hackney_pool, Plug.Conn, :telemetry]],
aliases: aliases()
xref: [exclude: [Finch, Plug.Conn, :telemetry]],
aliases: [aliases()]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aliases: [aliases()]
aliases: aliases()

@savhappy The mix test.integrations task in CI is unavailable because this was changed to a list when the aliases/0 function already returns a list. Reverting back should get you running

@@ -298,32 +298,64 @@ defmodule Sentry.Config do
The maximum number of attempts to send an event to Sentry.
"""
],
hackney_opts: [
finch_opts: [
type: :keyword_list,
default: [pool: :sentry_pool],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe pool: :sentry_pool is not a valid option for Finch? But it also looks like finch_opts is not used. Maybe it is best to shift to allowing a separation between Finch request_opts vs start_link opts? Sentry may not need to do intense validation since Finch also uses nimble_options under the hood

Copy link
Collaborator Author

@savhappy savhappy Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jjcarstens for the review 💜

You're right! :sentry_pool isn't valid. The Finch config options were just placeholder until we decide what options to expose. Which of the pool options do we want to support? @whatyouhide or @jjcarstens thoughts?
Maybe it makes sense to have a catch all like you (@jjcarstens) mentioned configuration option without the need to handle validation.

    finch_pool_opts: [
      type: :keyword_list,
      default: [size: 50, conn_max_idle_time: 5000],
      doc: """
      Start link pool ptions to be passed to `finch`....
      """
    ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :hackney_opts was switched to soft deprecation, but this Hackney client was totally removed which I assume is equally as breaking. Is there a specific reason not to leave it in until hackney is hard deprecated?

@@ -6,7 +6,7 @@ if config_env() == :test do
tags: %{},
enable_source_code_context: true,
root_source_code_paths: [File.cwd!()],
hackney_opts: [recv_timeout: 50, pool: :sentry_pool],
finch_opts: [recv_timeout: 50],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
finch_opts: [recv_timeout: 50],
finch_opts: [receive_timeout: 50],

According to t:Finch.request_opt(), this should be :receive_timeout

@whatyouhide
Copy link
Collaborator

@savhappy do you have an ETA for when you'd be able to make some progress on this?

@savhappy
Copy link
Collaborator Author

savhappy commented Mar 3, 2025

@whatyouhide working on this today. I need to add back in the Hackney client like @jjcarstens mentions so no breaking changes are introduced and await feedback on finch options to expose. After this, ready for another review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch from Hackney to Finch as the default HTTP client
4 participants